package com.zyf.wjy.controller;

import com.zyf.wjy.entity.User;
import com.zyf.wjy.service.NewsService;
import com.zyf.wjy.service.StatisticsService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Map;

/**
 * 首页控制器
 */
@Controller
public class IndexController {
    
    @Autowired
    private StatisticsService statisticsService;
    
    @Autowired
    private NewsService newsService;
    
    /**
     * 系统首页
     */
    @GetMapping("/index")
    public String index(HttpSession session, Model model) {
        User currentUser = (User) session.getAttribute("currentUser");
        model.addAttribute("currentUser", currentUser);
        
        // 获取统计数据
        Map<String, Object> statistics = statisticsService.getDashboardStatistics();
        model.addAttribute("statistics", statistics);
        
        // 获取最新公告
        model.addAttribute("topNews", newsService.findTopNews());
        
        return "index";
    }
}

